<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

Loader::loadUserClass('MemberController', false, 'admin');

class Admin_MemberController extends MemberController
{
    protected function _initMember() {
        if(!$_SESSION[RlModel::ISFREE]) {
            showmessage($this->_lang['member_not_free']);
        }
    }
    
    public function profileAction() {
        if($_POST['doeditpass']) {
            if(!is_password($_POST['password'])) {
                showmessage($this->_lang['error_password'], ADMIN_NAME.'?m=admin&c=member&a=profile');
            }
            
            if($_POST['password'] != $_POST['password_confirm']) {
                showmessage($this->_lang['two_password_not_equal'], ADMIN_NAME.'?m=admin&c=member&a=profile');
            }
            
            $salt = random(6);
            $password = password($_POST['password'], $salt);
            $this->getRl()->updateAdmin(array('password' => $password, 'salt' => $salt), array('userid' => $_SESSION[RlModel::USERID]));
            showmessage($this->_lang['admin_password_edit_success'], ADMIN_NAME.'?m=admin&c=member&a=profile');
        } elseif($_POST['doeditgroup']) {
            $_SESSION[RlModel::FORCE_QQ] = $_POST['force_qq'] == 1 ? 1 : 0;
            $this->getRl()->updateAdmin(array('force_qq' => $_SESSION[RlModel::FORCE_QQ]), array('userid' => $_SESSION[RlModel::USERID]));
            showmessage($this->_lang['admin_edit_success'], ADMIN_NAME.'?m=admin&c=member&a=profile');
        }
        
        $this->_view->assign('force_qq', $_SESSION[RlModel::FORCE_QQ]);
        $this->_view->display('member_setting');
    }
}